<?php 
    use app\modules\cn\models\RankingAll;
    use app\modules\cn\models\ExerciseList;
    use app\modules\cn\models\ExerciseListDetail;
    $model = new ExerciseList();

    $userId = Yii::$app->session->get('userId');
?>
<link rel="stylesheet" href="/cn/css/exerciseNew/listenIndex.css?v=1.1">
<script src="https://file.viplgw.cn/ui/public/lib/vue/vue.js"></script>

<section id="readIndex">
    <div class="readIndexCover">
        <p class="title"><a href="/cn/exercise/practice">做题练习</a> > <span>听力练习</span></p>

        <div class="readIndexContent">
            <div class="contentLeft">
                <!--      一级分类          -->
                <div class="oneLevel">
                    <a href="/cn/exercise/listen?category=all" class="onelevelitem <?php echo $category=='all' ? 'on':''?>">全部剑雅</a>
                    <a href="/cn/exercise/listen?category=type" class="onelevelitem <?php echo $category=='type' ? 'on':''?>">按题型练</a>
                    <a href="/cn/exercise/listen?category=topic" class="onelevelitem <?php echo $category=='topic' ? 'on':''?>">按话题练</a>
                    <a href="/cn/exercise/listen?category=level" class="onelevelitem <?php echo $category=='level' ? 'on':''?>">按难度练</a>
                </div>
                <!--      二级分类          -->
                <div class="twoLevel">
                    <?php if (!empty($datelist)): ?>
                        <?php if ($category == 'all'): ?>
                            <?php foreach ($datelist as $key => $value): ?>
                            <a href="/cn/exercise/listen?category=<?php echo $category?>&cate_id=<?php echo $value['cate_id']?>" class="twolevelitem <?php echo $cate_id == $value['cate_id'] ? 'on' : ''?>"><?php echo $value['name'] ?></a>
                            <?php endforeach ?>
                        <?php else: ?>
                            <?php foreach ($datelist as $key => $value): ?>
                                <a href="/cn/exercise/listen?category=<?php echo $category?>&category_id=<?php echo $value['id']?>" class="twolevelitem <?php echo $category_id == $value['id'] ? 'on' : ''?>"><?php echo $value['name'] ?></a>
                            <?php endforeach ?>
                        <?php endif ?>
                        
                    <?php endif ?>
                </div>
                <!--      广告   难度和话题才有          -->
                <?php if (in_array($category,['level', 'topic'])): ?>
                    <div class="advaImg"><img src="/cn/images/exerciseNew/12@2xNew.png" alt=""></div>
                <?php endif ?>
                
                <?php if ($list): ?>
                    <?php if ($category == 'all') {?> <!-- 全部剑雅真题 -->
                        <?php foreach ($list as $key => $value): ?>
                            <p class="typeTitle"> <?php echo $key?></p>
                            <div class="readList">
                            <?php foreach ($value as $k => $v): ?>
                                <?php
                                    $vid = $v['content_id'];
                                    // $sessionid = 'pid'.$vid;
                                    // $resultid = Yii::$app->session->get($sessionid);
                                    // if(!$resultid){
                                        $resultid = RankingAll::find('resultid')->where(['userid' =>$userId,'typeid' =>1,'pid' =>$vid])->andWhere(['not', ['testid' => null]])->orderBy('id desc')->distinct()->asArray()->One();
                                        $resultid = $resultid['resultid'];
                                    // }
                                    // f_d($resultid);
                                    // 查询重复名词做题次数 根据题号累加
                                    $name = $v['name'];
                                    $vount = 0; // 练习人数
                                    $dal = $model->getlistenexercisedotest($vid);
                                    // f_d($dal);
                                    $allnumber = 0; // 所有做题数
                                    $allnum = 0; // 所有题数
                                    $alltruenumber = 0; // 所有正确题数
                                    // $num = 0;
                                    foreach ($dal as $vcc)
                                    {
                                        $vount = $vount + $vcc['viewCount'];
                                        $id = $vcc['content_id'];
                                        // 总数
                                        $num = count(ExerciseListDetail::find()->where(['pid' =>$id])->asArray()->All()); 
                                        $allnum = $allnum + $num;
                                        // 做题数
                                        $number = count(RankingAll::find()->where(['userid' =>$userId,'typeid' =>1,'pid' =>$id, 'resultid'=>$resultid])->andWhere(['not', ['testid' => null]])->asArray()->All()); 
                                        $allnumber = $allnumber + $number;
                                        // 正确
                                        $truenumber = count(RankingAll::find()->where(['userid' =>$userId,'result'=>1,'typeid' =>1,'pid' =>$id])->andWhere(['not', ['testid' => null]])->asArray()->All()); 
                                        $alltruenumber = $alltruenumber + $truenumber;
                                    }
                                ?>
                                <!-- 未做 noDo  已做 isDo -->
                                <div class="readTypeItem ">
                                    <div class="goCover"><a href="/cn/exercise/listen-detail?content_id=<?php echo $v['content_id']?>" class="goBtn">去练习</a></div>
                                    <div class="<?php echo $allnumber>0 ? 'isDo' : 'noDo'?>"><?php echo $allnumber>0 ? '已做' : '未做'?></div>
                                    <div class="itemImg">
                                        <img src="<?php echo $v['title_image']?$v['title_image']:''?>" alt="">
                                        <p class="itemSec"><?php echo $v['section_name']?></p>
                                    </div>
                                    <div class="updateCover">
                                        <div class="peopleNum">
                                            <p>已有<?php echo $v['viewCount']?>人参加练习</p>
                                            <span>一周前更新题库</span>
                                        </div>
                                        <div class="topicJd"><?php echo $allnumber?>/<?php echo $allnum?></div>
                                    </div>
                                </div>
                            <?php endforeach ?>
                            </div>
                        <?php endforeach ?>
                        <?php } elseif ($category == 'topic' || $category == 'level' || $category == 'type') {?>  <!-- 话题 难度-->

                            <?php foreach ($list as $key => $value): ?>
                            <p class="typeTitle"><?php echo $key?></p>
                            <div class="readList">
                                <!-- 未做 noDo  已做 isDo -->
                                <?php foreach ($value as $k => $v): ?>
                                <?php
                                    $vid = $v['content_id'];
                                    // $sessionid = 'pid'.$vid;
                                    // $resultid = Yii::$app->session->get($sessionid);
                                    // if(!$resultid){
                                        $resultid = RankingAll::find('resultid')->where(['userid' =>$userId,'typeid' =>1,'pid' =>$vid])->andWhere(['not', ['testid' => null]])->orderBy('id desc')->distinct()->asArray()->One();
                                        $resultid = $resultid['resultid'];
                                    // }

                                    // 查询重复名词做题次数 根据题号累加
                                    $name = $v['name'];
                                    $vount = 0; // 练习人数
                                    $dal = $model->getlistenexercisedotest($vid);
                                    // f_d($dal);
                                    $allnumber = 0; // 所有做题数
                                    $allnum = 0; // 所有题数
                                    $alltruenumber = 0; // 所有正确题数
                                    // $num = 0;
                                    foreach ($dal as $vcc)
                                    {
                                        $vount = $vount + $vcc['viewCount'];
                                        $id = $vcc['content_id'];
                                        // 总数
                                        $num = count(ExerciseListDetail::find()->where(['pid' =>$id])->asArray()->All()); 
                                        $allnum = $allnum + $num;
                                        // 做题数
                                        $number = count(RankingAll::find()->where(['userid' =>$userId,'typeid' =>1,'pid' =>$id, 'resultid'=>$resultid])->andWhere(['not', ['testid' => null]])->asArray()->All()); 
                                        $allnumber = $allnumber + $number;
                                        // 正确
                                        $truenumber = count(RankingAll::find()->where(['userid' =>$userId,'result'=>1,'typeid' =>1,'pid' =>$id])->andWhere(['not', ['testid' => null]])->asArray()->All()); 
                                        $alltruenumber = $alltruenumber + $truenumber;
                                    }
                                ?>
                                <div class="readTypeItem ">
                                    <div class="goCover"><a href="/cn/exercise/listen-detail?content_id=<?php echo $v['content_id']?>" class="goBtn">去练习</a></div>
                                    <div class="<?php echo $allnumber>0 ? 'isDo' : 'noDo'?>"><?php echo $allnumber>0 ? '已做' : '未做'?></div>
                                    <div class="itemImg">
                                        <img src="<?php echo $v['image']?$v['image']:''?>" alt="">
                                        <p class="itemSec"><?php echo $v['name']?></p>
                                    </div>
                                    <div class="updateCover">
                                        <div class="peopleNum">
                                            <p>已有<?php echo $v['viewCount']?>人参加练习</p>
                                            <span>一周前更新题库</span>
                                        </div>
                                        <div class="topicJd"><?php echo $allnumber?>/<?php echo $allnum?></div>
                                    </div>
                                </div>
                                <?php endforeach ?>
                            </div>
                            <?php endforeach ?>
                            
                        <?php } ?>
                    
                <?php endif ?>

            </div>

            <div class="contentRight">
                <p class="rightTitle">最新优惠活动</p>
                <div class="rightImg">
                    <a href="https://p.qiao.baidu.com/cps/chat?siteId=16998561&userId=33849315&siteToken=0848542c0e71b685b68768fcec8e99ef">
                        <img src="/cn/images/exerciseNew/youhui1.png" alt="">
                    </a>
                </div>
                <?php if ($banner&&$banner['image2']): ?>
                    <div class="rightImg">
                        <a href="<?php echo $banner['image_url2']?$banner['image_url2']:''?>">
                            <img src="<?php echo $banner['image2']?$banner['image2']:''?>" alt="">
                        </a>
                    </div>
                <?php endif ?>
                
            </div>
        </div>
    </div>
</section>


<script src="/cn/js/exerciseNew/listenIndex.js?v=1.1"></script>